import request from '../../utils/request/index.js';

// 登录---获取验证码
export const code = (params) => {
  const options = {
    url: '/starlink-api/user/code',
    data: params,
  };
  return request.post(options);
};

// 登录---登录
export const login = (params) => {
  const options = {
    url: '/starlink-api/user/login?n=' + new Date().getTime(),
    data: params,
  };
  return request.post(options);
};

// 登录---获取用户登录信息
export const currentUser = () => {
  const options = {
    url: '/starlink-api/user/currentUser?n=' + new Date().getTime(),
  };
  return request.get(options);
};

// 登录---退出
export const logout = () => {
  const options = {
    url: '/starlink-api/user/logout?n=' + new Date().getTime(),
  };
  return request.get(options);
};

if (process.env.NODE_ENV === "development") {
  console.log("开发环境");
} else {
  console.log("生产环境");
}

// 钉钉登录
export const getDDCode = () => {
  console.log(dd, '---引入钉钉的信息---')
  return new Promise((resolve, reject) => {
    if (dd.env.platform !== 'notInDingTalk') {
      dd.ready(function() {
        // 获取免登授权码code
        dd.runtime.permission.requestAuthCode({
          //企业id
          corpId:window.location.host === "ssc.homedo.com" ? 'ding948f3dd52dabcbd835c2f4657eb6378f' : 'ding8d81cc4f021eb9c64ac5d6980864d335',
          // corpId: process.env.NODE_ENV === "development" ? 'ding8d81cc4f021eb9c64ac5d6980864d335' : 'ding948f3dd52dabcbd835c2f4657eb6378f',
          // corpId: 'ding948f3dd52dabcbd835c2f4657eb6378f', // pro生产
          onSuccess: function(result) {
            const code = result.code
            resolve(code)
          },
          onFail: function(err) {
            reject(`获取钉钉授权码失败:${JSON.stringify(err)}`)
          },
        })
      })
    } else {
      reject('非钉钉平台')
    }
  })
}
// 修改密码
export const saveLoginPassword = (data) => {
  const options = {
    url: '/starlink-api/pc/bpmApi/saveLoginPassword',
    data:data
  };
  return request.post(options);
};

// 发送邮箱验证码接口
export const getLoginEmailVerificationCode = (data) => {
  const options = {
    url: '/starlink-api/pc/bpmApi/getLoginEmailCode?email='+data,
  };
  return request.post(options);
};
// 发送短信验证码接口
export const getMobileVerificationCode = (data) => {
  const options = {
    url: '/starlink-api/pc/bpmApi/getMobileCode?phoneNumber='+data,
  };
  return request.post(options);
};
// 获取邮箱
export const getEamilByMobile = (data) => {
  const options = {
    url: '/starlink-api/pc/bpmApi/getEamilByMobile?mobile='+data,
  };
  return request.post(options);
};
